home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / domv.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  1KB  |  54 lines

  1. #include "kiss.h"
  2.  
  3. int domv (Stringstack s)
  4. {
  5.     register int
  6.     opt,
  7.     i,
  8.     ret = 0;
  9.     MvFlags
  10.     fl = { 0, 0, 0 };
  11.     struct stat
  12.     destbuf;
  13.  
  14.     while ( (opt = getopt (s.nstr, s.str, "ivph")) != -1 )
  15.     switch (opt)
  16.     {
  17.         case 'i':
  18.         fl.interactive = 1;
  19.         break;
  20.         case 'v':
  21.         fl.verbose = 1;
  22.         break;
  23.         case 'p':
  24.         fl.protect = 1;
  25.         break;
  26.         case 'h':
  27.         default:
  28.         error ("Bad commandline.\n"
  29.                "Usage: %s [-ivp] sourcefile destfile\n"
  30.                "       %s [-ivp] sourcefile(s) destdir\n"
  31.                "Where:\n"
  32.                "    -i: interactive mode, ask confirmation before "
  33.                     "overwriting\n"
  34.                "    -v: verbose mode: show what's happening\n"
  35.                "    -p: protect existing files, never overwrite them\n"
  36.                , progname, progname);
  37.     }
  38.  
  39.     /* need at least 2 args */
  40.     if (s.nstr - optind < 2)
  41.     error ("need at least 2 arguments");
  42.  
  43.     /* is last entry a dir? */
  44.     if (! stat (s.str [s.nstr - 1], &destbuf) && S_ISDIR (destbuf.st_mode))
  45.     for (i = optind; i < s.nstr - 1; i++)
  46.         ret += movefiletodir (s.str [i], s.str [s.nstr - 1], fl);
  47.     else if (s.nstr - optind > 2)
  48.     error ("more than 1 file can only be moved to destination directory");
  49.     else
  50.     ret += movefiletofile (s.str [optind], s.str [s.nstr - 1], fl);
  51.  
  52.     return (ret);
  53. }
  54.